//给h1的三个span和button设置点击事件
var span1 = document.querySelector('h1>span:nth-of-type(1)')
span1.onclick = function () {
    location.href = "../index.html"
}
var span2 = document.querySelector('h1>span:nth-of-type(2)')
span2.onclick = function () {
    location.href = "./12.html"
}
var span3 = document.querySelector('h1>span:nth-of-type(3)')
span3.onclick = function () {
    location.reload()
}
var button = document.querySelector('h1>button')
button.onclick = function () {
    location.reload()
}
console.log(location.href)
var url = location.href
var wangzhi = getUrlParams(url)
console.log(wangzhi)
let { brandtitleid } = wangzhi
let { brandname } = wangzhi
let {categoryid}=wangzhi
let { span11 } = wangzhi

span3.innerText = `${brandname}>`

var main = document.querySelector('main')
// console.log(main)
var ul = document.querySelector('ul')
var xhr = new XMLHttpRequest()
xhr.open('get', `http://chst.vip:1234/api/getbrandproductlist?brandtitleid=${brandtitleid}`)
xhr.send()
xhr.onreadystatechange = function () {
    if (xhr.status === 200 && xhr.readyState === 4) {
        var x = JSON.parse(xhr.responseText).result
        console.log(x)
        var html = ""
        x.forEach(item => {
            html += `
            <li value=${item.productId} class=${item.productName}>
            ${item.productImg}
                <h4>${item.productName}</h4>
                <b>${item.productPrice}</b>
                <span>${item.productQuote}</span>
                <i>${item.productCom}</i>
            </li>`
        });
        ul.innerHTML = html
        var li=document.querySelectorAll('main>ul>li')
        console.log(li)
       li.forEach((item)=>{
           item.onclick=function(){
               var productid=item.getAttribute('value')
               var y=item.getAttribute('class')
               console.log(y)
              
             location.href=`./12跳转跳转页.html?categoryid=${categoryid}&productid=${productid}&span11=${span11}&span12=${y}`
           }
       })
    }
}


















//书写返回index.html功能
var fanhui = document.querySelector('header>a')
fanhui.onclick = function () {
    location.href = "../index.html"
}